#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;

string s,t;
int f[3030][3030];
pii from[3030][3030];
int lens,lent;

void dfs(int x,int y){
    if(x<= 0 || y<=0) return ;
    dfs(from[x][y].fs,from[x][y].sc);
    cout<<s[x];
}
void upd(int i,int j,int x,int y){
    if(s[x] == t[y]) from[i][j] = {x,y};
    else from[i][j] = from[x][y];
}
int main(){
    // debug;
    ios;
    cin>>s>>t;
    lens = s.length(),lent = t.length();
    s = "#" + s; t = "^"+t;
    for(int i = 1;i<=lens;i++){
        for(int j = 1;j<=lent;j++){
            if(s[i] == t[j]) {
                f[i][j] = f[i-1][j-1] + 1;
                upd(i,j,i-1,j-1);
            }else{
                f[i][j] = max(f[i-1][j],f[i][j-1]);
                if(f[i-1][j] > f[i][j-1]) upd(i,j,i-1,j);
                else upd(i,j,i,j-1);
            } 
        }
    }
    int x = from[lens][lent].fs,y = from[lens][lent].sc;
    dfs(x,y);
    if(s[lens] == t[lent]) cout<<s[lens];

    
    return 0;
}
